package com.lhj.springboot3.core.service;

import com.lhj.springboot3.core.bean.UserEntity;
import com.lhj.springboot3.core.event.LoginSuccessEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author lhj
 * @Date 2024/6/30 10:29
 */
@Slf4j
@Service
public class IntegralService  {
    
    public void sendIntegral(String username) {
        log.info("赠送 {} 用户20积分", username);
    }
    
    @Order(1)
    @EventListener
    public void sendIntegralOnEvent(LoginSuccessEvent event) {
        log.info("监听赠送积分事件: {}", event.toString());
        UserEntity source = (UserEntity) event.getSource();
        log.info("赠送 {} 用户20积分", source.getUserName());
    }
    
}
